
Namespace Validation

    Public Class StringLengthRuleEventArgs
        Inherits RuleEventArgs

#Region " Declarations "

        Private _enumAllowNullString As AllowNullString = Validation.AllowNullString.No
        Private _intMaximumLength As Integer = -1
        Private _intMinimumLength As Integer = -1

#End Region

#Region " Properties "

        Public Property AllowNullString() As AllowNullString
            Get
                Return _enumAllowNullString
            End Get
            Set(ByVal Value As AllowNullString)
                _enumAllowNullString = Value
            End Set
        End Property

        Public Property MaximumLength() As Integer
            Get
                Return _intMaximumLength
            End Get
            Set(ByVal Value As Integer)
                _intMaximumLength = Value
            End Set
        End Property

        Public Property MinimumLength() As Integer
            Get
                Return _intMinimumLength
            End Get
            Set(ByVal Value As Integer)
                _intMinimumLength = Value
            End Set
        End Property

#End Region

#Region " Constructor "

        Public Sub New(ByVal enumAllowNullString As AllowNullString, ByVal intMinimumLength As Integer, ByVal intMaximumLength As Integer, ByVal strCustomMessage As String, ByVal strPropertyFriendlyName As String, ByVal strPropertyName As String, ByVal strRuleSet As String)
            MyBase.New(strPropertyName, strPropertyFriendlyName, strRuleSet, strCustomMessage)

            If intMaximumLength < 1 Then
                Throw New ArgumentOutOfRangeException("intMaximumLength", "MaximumLength must be greater than 0.")

            ElseIf intMaximumLength < intMinimumLength Then
                Throw New ArgumentOutOfRangeException("intMaximumLength", "MaximumLength must be greater than or equal to the MinimumLength.")
            End If

            _intMinimumLength = intMinimumLength
            _intMaximumLength = intMaximumLength
            _enumAllowNullString = enumAllowNullString
        End Sub

        Public Sub New(ByVal enumAllowNullString As AllowNullString, ByVal intMaximumLength As Integer, ByVal strCustomMessage As String, ByVal strPropertyFriendlyName As String, ByVal strPropertyName As String, ByVal strRuleSet As String)
            MyBase.New(strPropertyName, strPropertyFriendlyName, strRuleSet, strCustomMessage)

            If intMaximumLength < 1 Then
                Throw New ArgumentOutOfRangeException("intMaximumLength", "MaximumLength must be greater than 0.")
            End If

            _intMinimumLength = -1
            _intMaximumLength = intMaximumLength
            _enumAllowNullString = enumAllowNullString
        End Sub

        Public Sub New(ByVal e As StringLengthValidatorAttribute, ByVal strPropertyName As String)
            MyBase.New(strPropertyName, e.PropertyFriendlyName, e.RuleSet, e.CustomMessage)
            _enumAllowNullString = e.AllowNullString

            If e.MaximumLength < 1 Then
                Throw New ArgumentOutOfRangeException("MaximumLength", "MaximumLength must be greater than 0.")

            ElseIf e.MaximumLength < e.MinimumLength Then
                Throw New ArgumentOutOfRangeException("MaximumLength", "MaximumLength must be greater than or equal to the MinimumLength.")
            End If

            _intMaximumLength = e.MaximumLength
            _intMinimumLength = e.MinimumLength
        End Sub

#End Region

    End Class

End Namespace
